/*
 * @Author: fangquan
 * @Date: 2020-06-10 13:38:32
 * @Last Modified by: fangquan
 * @Last Modified time: 2020-06-10 17:47:58
 * @Usage 公共接口集合
 */

import request from "@/utils/request";
import config from "@/config";

import { formatParams } from "@/utils/common";

let domain =
  process.env.VUE_APP_TYPE == "online"
    ? "http://xuehuli.com"
    : process.env.VUE_APP_TYPE == "production"
    ? "http://dev.yatiku.com"
    : "";

const EXTRA = {
  showLoading: false,
};

/**
 * 获取access_token
 */
export let getAccessToken = (params) =>
  request.post(
    `${domain}/app/v1/getAccessToken`,
    {
      brandType: config.brandType,
      clientType: config.clientType,
      clientVersion: config.clientVersion,
      ...params,
    },
    EXTRA
  );

/**
 * 获取AppId
 */
export let getAppId = (params) =>
  request.post(`${domain}/activity/getApAc`, params, EXTRA);

/**
 * 获取用户信息
 */
export let getUserInfo = (params) =>
  request.post(`${domain}/activity/getUserInfo`, params, EXTRA);

/**
 * 获取所有用户信息
 */
export let getUserAllInfo = (params) =>
  request.post(`${domain}/activity/getUserAllInfo`, params, EXTRA);

/**
 * 微信JS-SDK验证
 */
export let checkWechatSDK = (params) =>
  request.post(
    `${domain}/activity/jsapiTicket?urltimer=${new Date().getTime()}`,
    {
      url: location.href,
      accid: formatParams().accId || 1,
      access_token: localStorage.getItem("access_token") || "",
      ...params,
    },
    EXTRA
  );
/**
 * 获取教师二维码
 */
export let getTeacherQrcode = (params) =>
  request.get(
    `${domain}/activity/wxUserAcc/share/catalog/getShareActivityIdByRecode`,
    params,
    {
      showLoading: false,
      showToast: false,
    }
  );

/**
 * 手机登录
 */
export let loginByTel = (params) =>
  request.post(`${domain}/activity/loginByTel`, params);

/**
 * 获取省市区信息
 */
export let listAddress = (params) =>
  request.get(`${domain}/tool/address/all`, params);

/**
 * 上传文件到OSS
 */
export let uploadFile = (params) =>
  request.post("http://app.yatiku.com/tool/uploadFileOss", params, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });

/**
 * 写公共参数cookie
 */
export let writeCookie = (params) =>
  request.post(`${domain}/app/v1/tool/writeCookie`, params);

/**
 * 上传base64图片
 */
export let uploadBase64Img = (params) =>
  request.post(`${domain}/tool/uploadBase64Img`, params);

/**
 * 清除cookie
 */
export let cleanCookie = (params) =>
  request.get(`${domain}/activity/cleanCookie`, params);
